package com.honglang.struts2.action;


import java.io.File;
import java.util.List;

import com.honglang.common.tools.Constants;
import com.honglang.entity.FileSys;
import com.honglang.service.FileSysService;
import com.opensymphony.xwork2.Action;

public class FileSysManagerAction extends BaseAction{
	
	private FileSysService fileSysService;

	
	
	/**
	 * prePare manager files which are not image ;
	 * @return
	 */
	public String preOtherFileManager(){
		
		String pageNoStr = this.getRequest().getParameter("pageNo");
		int pageNo = Constants.DEFAULT_PAGE_NO;
		if(null != pageNoStr){
			pageNo = Integer.valueOf(this.getRequest().getParameter("pageNo"));
		}
		this.getRequest().setAttribute("pager", this.fileSysService.getNonImageFileInPager(Constants.NON_PHOTO_FILE_PAGE_SIZE, pageNo));
		return Action.SUCCESS;
	}
	
	
	/**
	 * delete fileSys;
	 * @return
	 */
	public String delete(){
		String fileSysId = this.getRequest().getParameter("fId");
		if(null != fileSysId){
			FileSys fileSys = this.getFileSysService().getFileSys(Integer.valueOf(fileSysId));
			new File(fileSys.getAbsoluteUrl()).delete();
			this.getFileSysService().delete(fileSys);
		}
		return Action.NONE;
	}
	
	
	/**
	 * batch delete fileSys
	 * @return
	 */
	public String batchDelete(){
		String fileSysIds = this.getRequest().getParameter("fIds");
		if(null != fileSysIds){
			List<FileSys> fileSysList = this.getFileSysService().getFileSysByIds(fileSysIds);
			for(FileSys fileSys: fileSysList){
				new File(fileSys.getAbsoluteUrl()).delete();
			}
			this.getFileSysService().delete(fileSysList);
			
		}
		return Action.NONE;
	}
	
	
	
	public FileSysService getFileSysService() {
		return fileSysService;
	}

	public void setFileSysService(FileSysService fileSysService) {
		this.fileSysService = fileSysService;
	}
	
	
}
